<template>
	<view>
		<view style="display: flex;align-items: center;width: 100vw;flex-direction: row;background-color: #fff;">
			<view @click="navitosearch" style="vertical-align: middle;width: calc(100vw - 80px); padding: 5px;margin: 5px 10px; border-radius: 15px;border: #888 1px solid;display: flex;align-items: center;">
				<text class="iconfont icon-chazhao" style="padding-right: 5px;"></text>
				<input disabled="true" style="outline-color: invert;flex:1; outline-style: none;outline-width: 0px;border: none;border-style: none;text-shadow: none; -webkit-appearance: none;-webkit-user-select: text;outline-color: transparent;box-shadow: none;outline: none;border-radius: 0;"/>
			</view>
			<view @click="navitosao" class="iconfont icon-saomiao" style="color: #fd6137; padding: 5px;margin-right: 5px; font-size: 20px;">
			</view>
		</view>
		
		<view class="classify">
			<view class="left">
				<view style="overflow-y: scroll;overflow-x: hidden;height:calc(100vh - 90px);">
					<view style="display: flex;flex-wrap: wrap;flex-direction: column;" v-if="JSON.stringify(datacategory)!='[]'">
						<view  v-for="(item,index) in datacategory"  :key="index" style="color: #999;line-height: 100%;">
							<view v-if="index==selecteditem " style=" padding: 20px 0;color: #e85a71;display: flex; flex-direction: row;position: relative;" @click="selectItem(index,item.mc)">
								<view style="width: 4px;background-color: #f00;"></view>
								<view style="margin-left: 10px;color: #f00;font-weight: 700;font-size: 14px;">{{item.mc}}</view>
								<view v-if="item.sl>0" style="position: absolute;top: 0;right: 0;color: #fff; background-color: #e85a71;border-radius: 16px;padding: 0 5px;font-size: 12px;">
									{{item.sl}}
								</view>
							</view>
							<view v-else style="padding: 20px 0 20px 14px;font-size: 14px; background-color: #fff;display: flex;position: relative;" @click="selectItem(index,item.mc)">
							<view>{{item.mc}}</view>
							 <view v-if="item.sl>0" style="position: absolute;top: 0; right: 0;color: #fff;; background-color: #e85a71;border-radius: 16px;padding: 0 5px;font-size: 12px;">
							 	{{item.sl}}
							 </view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="right">
				<view v-if="datacategory[selecteditem].children!=undefined" style="height:45px ;width: calc(100vw - 80px);background-color: #fff;">
					<scroll-view   style="height: 40px;width: calc(100vw - 80px);white-space:nowrap ;white-space: nowrap;align-items: center;" scroll-x="true">
						<block v-if="datacategory[selecteditem].mc!='全部'" v-for="(item,index) in datacategory[selecteditem].children" :key="index" >
							<view @click="selectxl(index)" style="display: inline-block;white-space: nowrap;height: 100%;font-size: 14px;align-items: center;flex-direction: row;margin-left: 10px;">
								<view style="display: flex;flex-direction: row;align-items: center;height: 100%;padding:0 5px;"><view style="border: 1px solid #EFEFF4;padding: 2px 5px;border-radius: 3px;"  :style="{'color':!item.isselected?'#333':'#fd6137','border-color':!item.isselected?'#EFEFF4':'#fd6137'}">{{item.mc}}</view> </view>
							</view>
						</block>
					</scroll-view>
				</view>
				<scroll-view @scrolltolower="loadmore" scroll-y=true style="overflow-y: scroll;overflow-x: hidden;height:calc(100vh - 50px);width: calc(100vw - 90px);background-color: #eee;" >
					<view v-if="datacategory[selecteditem].products!=undefined"  style="display: flex;flex-wrap: wrap;flex-direction: column;">
						<view v-for="(item,index) in datacategory[selecteditem].products" :key="index" >
							<view style="display: flex;flex-direction: row;flex-wrap: wrap; margin-left:4px;margin-top: 10px; width:calc(100vw - 90px);background-color: #fff;">
							<view v-for="(product, index2) in item" :key='product.id' v-if="product.blockName!=''">
								<view v-if="product.blockName=='chooseprodcut_name1'" class="head-title">
									<view class="icon"></view> 
									<view class="head-cont">
										<view>{{product.data[0].style.colValue}}</view>
									</view>
								</view>
								<view style="display: flex;flex-direction: row;flex-wrap: wrap;" v-if="product.blockName=='chooseprodcut_image1_corner2'" >
									<view style="position: relative;width: 80px;height: 100%;">
										<image @click="navitogood(item,index)"  :src="pic_address + product.data[0].style.colValue" @error="picerror(index)" style="width: 80px;height: 80px;padding:8px 3px;top: 0;left: 0;"></image> 
										<view style="position:absolute;top:8px ;left: 0;z-index: 1000;">
											<view style="padding: 1px 3px;background-color: springgreen;color: #fff;font-size: 12px;">{{product.data[1].style.colValue}}</view>
										</view>
										<view style="position:absolute;bottom:16px ;right: 0;z-index: 1000;">
											<view style="padding: 1px 3px;background-color: springgreen;color: #fff;font-size: 12px;">{{product.data[2].style.colValue}}</view>
										</view>
									</view>
								</view>
								<view style="width:calc(100vw - 240px) ;height: 100%;padding-left: 8px;padding-top: 10px;" v-if="product.blockName=='chooseprodcut_line1_nosplit'">
									<view v-for="(gdetail) in product.data" :key='gdetail.name'>
										<view style="color: #666;font-size: 14px; display: flex;flex-direction: row;align-items: center;">
										    <view style="min-width: 16vw;">{{gdetail.style.colText}}:</view>
											<view style="border-radius: 5px;min-width: 30vw;">{{gdetail.style.colValue==null?'':gdetail.style.colValue}}</view>
										</view>
									</view>
								</view>
								<view v-if="product.blockName=='chooseprodcut_numcol'" style="display: flex;flex-direction: row;line-height: 100%;height: 100%;align-items: center;">
									<view v-if="rowWriteBackRule!='addrow'" @click="navitogood(item,index)">
										<view v-if="product.data[0].style.colValue==0 && index==0" class="iconfont icon-jiahao" style="text-align: center;font-size: 20px;min-width: 50px;"></view>
										<view v-else style="color: #F55C23;text-align: center;">
											<view class="iconfont icon-bianji" ></view>
											<view style="font-size: 12px;margin-top: 5px;">操作数:{{product.data[0].style.colValue}}</view>
										</view>
									</view>
									<view @click="selectgood(product, index,index2,product.data[0].style.colValue)" v-else style="text-align: center;min-width: 50px;right: 5px;position: absolute;">
										<view v-if="product.data[0].style.colValue==1"  class="iconfont icon-xuanzhongduigou" style="color: #F55C23;font-size: 30px;"></view>
										<view v-else class="iconfont icon-xuanzhongduigou" style="color: #999;font-size: 30px;"></view>
									</view>
								</view>
							</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
		
		<view style="width: 100vw;height: 44px;display: flex;position: absolute;bottom: 0;z-index: 1000;">
			<view style="width: 75vw;background-color: #333;display: flex;z-index: 1000;" >
				<view style="position: relative;" v-if="rowWriteBackRule!='addrow'"><text class="iconfont icon-icozhuanhuan" style="font-size: 28px;color: #333;background-color: #f7d08d;border-radius: 50%;padding: 10px;margin: -10px 10px 0 10px;"></text>
					<view v-if="datacategory[0].sl!=undefined" style="position: absolute;top: -5px; right: 5px;color: #fff; background-color: #e85a71;border-radius: 16px;padding: 0 5px;font-size: 12px;">
						{{datacategory[0].sl}}
					</view>
				</view>
			</view>
			<view @click="navitodetail" style="width: 25vw;background-color: #e85a71;align-items: center;display: flex; justify-content: center;z-index: 800;">选好了</view>
		</view>
		
		<view v-if="iscontentdetail1"  @click="closemask" style="backface-visibility: hidden;top: 0;right: 0;left: 0;bottom: 0;position: fixed;overflow: hidden;width: 100vw;height: 100%;opacity: 1;background-color: rgba(0,0,0,0.4);z-index: 9000;">
			<view @click.stop="" :style="{'height':maskheight+'px'}" style="opacity: 1;background-color: #fff;z-index: 9000;bottom: 0px;position: absolute;width: 100vw;">
				<stylesku ref="stylesku" :pagename='pageName' :datalist='halfdatalist[0]' :pic_address='pic_address' :jsonoptions='jsonoptions' :divArea='halfDivArea'></stylesku>
			</view>
		</view>
		
	</view>
</template>

<script>
	var util = require("../../utils/util.js");
	var infolistutil = require("../../utils/infolistutil.js");
	var common = require("../../utils/api/common.js")
	var processInitialData = require("../../utils/processInitialData.js")
	import stylesku from "../../components/stylesku/stylesku"
	export default {
		components:{
			stylesku
		},
		data() {
			return {
				selecteditem:0,
				selectedtitle:'',
				goodindex:0,
				skuindex:0,
				skuitemindex:0,
				cartcount:0,
				skugood:[],
				goodsarr:[],
				ismask:false,
				skugoodnum:[],
				cartmask:false,
				cartarr:[],
				giftarr:[],
				summoney:0,
				code:'',
				isloadmore:true,
				pageName:'',
				templetName:'',
				rowWriteBackRule:'',
				modid:'',
				menuid:'',
				div:[],
				halfdatalist:[],
				divbar:{},
				divcategory:{},
				divlist:{},
				databar:[],
				datacategory:[],
				datalist:[],
				sumdatalist:[],
				datanostyle:[],
				pic_address:'',
				iscontentdetail1:false,
				maskheight:'370',
				jsonoptions:{},
				halfDivArea:'',
				halfconditions:{},
				conditions:{},
				ColNameQty:'',
				colNameSPU:'',
				colNameWriteBackBasedOn:'',
				productindex:0,
				skuselected:[],
				skuitemdata:{},
				rowWriteBackRule:'',
				categoryIsFilter:'',
				pageConditions:{"pageNumber": 1,"rowsPerPage": 20,"isAllData": true},
			}
		},
		onLoad:async function(options){
			var that = this
			this.pic_address = getApp().globalData.pic_address
			
			var title = options.title==undefined?'':options.title
			if(title!='')  uni.setNavigationBarTitle({title:title})
			var conditions = {}
			try{
				conditions = JSON.parse(options.conditions)
			}catch(e){}
			that.skuselected = JSON.parse(options.skuselected)
			console.log(that.skuselected)
			that.modid = options.modid
			that.menuid = options.menuid
			that.pageName = options.pagename
			that.templetName = options.templatename
			that.conditions = conditions
			that.jsonoptions = options
			var injson = common.requestStylePre(options)
			var url = getApp().globalData.app_address + '?method=saas_PageStyle&parse=json'
			uni.showLoading({ title: '加载中' })
			
			uni.request({
				url:url,
				data: injson,
				method: 'POST',
				header: {'content-type': 'application/x-www-form-urlencoded'},
				success: function(res) {
					
					var result = res.data;
					console.log(result)
					var div = result.data.div
					that.div = div
					that.categoryIsFilter = result.data.page.categoryIsFilter==undefined?'':result.data.page.categoryIsFilter
					that.$options.methods.getdatalist2(div,that,options,conditions)
				},
			})
			
			
			uni.$on("updatelist", (listtype, listindex,listblockindex, listitemindex, itemobj,pagename)=>{
				if(pagename!=this.pageName)return
				var item = that.halfdatalist[0][listblockindex].data[listitemindex]
				item.style = itemobj
				if(itemobj.itemchanged !=undefined && itemobj.itemchanged!= ''){
					var content = itemobj.itemcontent
					var itemchanged = itemobj.itemchanged
					var dddwcolumn = ''
					var itemcolumn = ''
					if(itemchanged!=undefined || itemchanged!= ''){
						dddwcolumn = itemchanged.split('.')[1]
						itemcolumn = itemchanged.split('@')[0]
					}
					for(var i=0;i<content.length;i++){
						if(dddwcolumn != '' && dddwcolumn == content[i].name){
							var dataList = that.halfdatalist[listindex]
							dataList.forEach((val) => {
								val.data.forEach((val2, index2, origin) => {
									if(val2.name == itemcolumn){
										if(index2 == 0){console.log(origin)}
										origin[index2].style.value = content[i].style.value
										origin[index2].style.colValue = content[i].style.value
										origin[index2].style.coldisplay = content[i].style.value
										origin[index2].style.ismodified = true
									}
								})
							})
							that.halfdatalist[listindex] = dataList
						}
					}
				}
				
				that.halfdatalist[0][listblockindex].data[listitemindex] = item
				
				var itemexpstr = util.gettagvalue(itemobj.tag,'computelist')
				if(itemexpstr!=''){
					itemexpstr = itemexpstr.replace(/'/g, '"').toString()
					var itemexp = JSON.parse(itemexpstr)
					var halfdatalist = that.halfdatalist[0]
					var skuitemdata = {}
					halfdatalist.forEach((val)=>{
						val.data.forEach((val2)=>{
							skuitemdata[val2.name] = val2.style.colValue
						})
					})
					itemexp.forEach((val)=>{
						halfdatalist.forEach((val2,index2)=>{
							val2.data.forEach((val3,index3)=>{
								if(val3.name == val){
									var ss = val3.style.expression
									var search = '#'
									var positions = []
									var index = ss.indexOf(search)
									var num = 0
									while(index !== -1){
										positions.push(index)
										index = ss.indexOf(search, index+1)
									}
									console.log(positions)
									var ps = []
									for (var i = 0; i < positions.length; i++) {
										if(i%2 == 0){
											var c = ss.substring(positions[i]+1, positions[i+1])
											ps.push(['#'+c+'#', skuitemdata[c]])
										}
									}
									ps.forEach((valps)=>{
										ss= ss.replace(valps[0], valps[1])
									})
									var productCode = uni.getStorageSync('productCode')
									var sessionId = uni.getStorageSync('sessionId')
									var projectCode = uni.getStorageSync('projectCode')
									var terminaltype = uni.getStorageSync('terminaltype')
									var dbId = uni.getStorageSync('dbId')
									var userId = uni.getStorageSync('userId')
									var userName = uni.getStorageSync('userName')
									var injson2 = '{"productCode":"' + productCode + '","terminalType":"' + terminaltype + '","projectCode":"' +
										projectCode + '","dbId":"' + dbId + '","templetName":"' + that.templetName + '","pageName":"' + that.pageName +
										'","menuId":"'+that.menuid+'","modId":"' + that.modid + '","sessionId":"' + sessionId + '","userId":"' + userId +
										'","userName":"' + userName + '","divArea":"' + that.jsonoptions.divArea + '","dataObject":"' + that.jsonoptions.dataObject + 
										'","colNameInput":"' + item.name + 
										'","colNameExp":"' + val + 
										'","expression":"' + ss + '"}';
									console.log(injson2)
									uni.request({
										url: getApp().globalData.app_address + '?method=saas_PageDivExpression&parse=json',
										data: injson2,
										method: 'POST',
										header: {'content-type': 'application/x-www-form-urlencoded'},
										success: function(res) {
											var result = res.data;
											var calcres = result.data
											val3.style.colValue = calcres
											val3.style.value = calcres
											val3.style.coldisplay = calcres
											val3.style.ismodified = true
											that.halfdatalist[0][index2].data[index3] = val3
											var itemchanged = util.gettagvalue(itemobj.tag,'itemchanged')
											var itemchangedarr = []
											if(itemchanged.indexOf(',')!=-1){
												itemchangedarr = itemchanged.split(',')
											}else{
												itemchangedarr.push(itemchanged)
											}
											itemchangedarr.forEach((valitem)=>{
												var valitemarr = valitem.split('=')
												if(valitem.indexOf(val3.name)!=-1){
													halfdatalist.forEach((val22,index22)=>{
														val22.data.forEach((val33,index33)=>{
															if(val33.name == valitemarr[0]){
																val33.style.colValue = calcres
																val33.style.value = calcres
																val33.style.coldisplay = calcres
																val33.style.ismodified = true
																that.halfdatalist[0][index22].data[index33] = val33
															}
														})
													})
												}
											})
											that.$forceUpdate()
										},
									})
									
								}
							})
						})
					})
				}
			})
			
			uni.$on("cancelsku", ()=>{
				this.iscontentdetail1 = false
			})
			
			uni.$on("ensuresku", (datalist,parenttype,pagename)=>{
				if(pagename!=this.pageName)return
				console.log(pagename)
				var skuitem = {}
				datalist.forEach((val)=>{
					val.data.forEach((val2)=>{
						skuitem[val2.name] = val2.style.colValue
					})
				})
				
				var ColNameQty = that.ColNameQty
				var colNameWriteBackBasedOn = that.colNameWriteBackBasedOn
				
				var product = that.datacategory[that.selecteditem]['products'][that.productindex]
				product.forEach((val2)=>{
					val2.data.forEach((val3)=>{
						if(val3.name == ColNameQty){
							val3.style.colValue = skuitem[ColNameQty]
						}
						if(val3.name == 'dldm'){
							skuitem['dm'] = val3.style.colValue
						}
					})
				})
				that.datacategory[that.selecteditem]['products'][that.productindex] = product
				var itemindex = undefined
				var skuselected = that.skuselected
				if(JSON.stringify(skuselected)!= '[]'){
					skuselected.forEach((val,index)=>{
						if(val[colNameWriteBackBasedOn] == skuitem[colNameWriteBackBasedOn]){
							itemindex = index
						}
					})
				}
				if(itemindex != undefined){
					if(skuitem[ColNameQty]>0){
						skuselected.splice(itemindex,1,skuitem)
					}else{
						skuselected.splice(itemindex, 1)
					}
				}else{
					skuselected.push(skuitem)
				}
				
				var datacategory = that.datacategory
				datacategory.forEach((val,index)=>{
					var dm = val.dm
					var sl = 0
					if(index == 0){
						skuselected.forEach((val2)=>{
							sl += parseInt(val2[ColNameQty])
						})
						val[ColNameQty] = sl
					}else{
						skuselected.forEach((val2)=>{
							if(val2.dm == dm){
								sl += parseInt(val2[ColNameQty])
							}
						})
						val[ColNameQty] = sl
					}
				})
				
				that.datacategory = datacategory
				
				console.log(that.datacategory)
				that.skuselected = skuselected
				console.log(skuselected)
				this.iscontentdetail1 = false
				
			})
		},
		
		methods:{
			
			async getdatalist2 (div,that,options,conditions){
				for (var index = 0; index < div.length; index++) {
					var val = div[index]
					var datastyle = val.style.colStyle
					var divBlocks = val.divClass.divBlocks
					var divArea = val.divArea
					var dataObject = val.style.dataObject
					
					if(divArea === 'dw_retrievebar'){
						that.divbar = val
					}else if(divArea === 'dw_category'){
						that.divcategory = val
					}else if(divArea === 'dw_datalist'){
						that.divlist = val
						options['divArea'] = divArea
						options['dataObject'] = dataObject
						that.ColNameQty= val.style.ColNameQty
						that.colNameSPU = val.style.colNameSPU
						that.colNameWriteBackBasedOn = val.style.colNameWriteBackBasedOn
						that.rowWriteBackRule = val.style.rowWriteBackRule
						if(that.rowWriteBackRule == 'addrow'){
							that.skuselected = []
						}
						that.jsonoptions = options
					}
					if(JSON.stringify(datastyle)!='[]'){
						var listindex = 0
						for(var i=0;i<datastyle.length;i++){
							if(datastyle[i].style.editStyle=='dddw' && datastyle[i].style.dddw.name!='d_nvo_uipage_dwc'&&datastyle[i].style.colVisible){
								datastyle[i].style['typeindex'] = listindex
								listindex++
								var multiselect = util.gettagvalue(datastyle[i].style.tag, 'multiselect')
								if(multiselect == 1){
									that.repeatByColName = datastyle[i].name
									that.repeatByColTag = datastyle[i].style.tag
								}
							}
						}
					}
					
					var temconditions = {}
					var blockstyle = []
					blockstyle = infolistutil.divblocktrans(divBlocks,datastyle)
					var replaceConditions = {}
					var divreplaceColumns = val.style.replaceColumns==undefined?[]:val.style.replaceColumns
					replaceConditions = processInitialData.replaceConditionstrans(replaceConditions, divreplaceColumns,conditions,'')
					var injson2 = common.requestDataPre(that.jsonoptions,divArea,dataObject,replaceConditions,temconditions,that.pageConditions )
					var url = getApp().globalData.app_address + '?method=saas_PageDivData&parse=json'
					const { data: res } = await infolistutil.post2(url, injson2);
					uni.hideLoading()
					var result = res.data;
					var divarea = divArea
					var valtype = val.type
					var datalisttemp = res.data.div.value
					var datalistpre = JSON.parse(JSON.stringify(datalisttemp))
					var datalist = []
					var DataObjectExtData = uni.getStorageSync('DataObjectExtData')
					if(divarea == 'dw_retrievebar'){
						that.databar = datalist
						that.olddatabar = JSON.parse(JSON.stringify(datalist))
					}else if(divarea == 'dw_category'){
						var id = ''
						var pid = ''
						var item = {}
						item['dm'] = '00'
						item['handle'] = 0
						item['level'] = 1
						item['mc'] = '全部'
						item['parentdm'] = ''
						item['selected'] = 0
						datalisttemp.unshift(item)
						console.log(res)
						that.datacategory = util.structureTreeData2(datalisttemp, id = "dm", pid ="parentdm")
						console.log(that.datacategory)
						that.olddatacategory = JSON.parse(JSON.stringify(that.datacategory))
					}else if(divarea == 'dw_datalist'){
						var skuselected = that.skuselected
						var ColNameQty = that.ColNameQty
						var colNameSPU = that.colNameSPU
						console.log(res)
						console.log(result)
						console.log(JSON.parse(JSON.stringify(datalisttemp)))
						if(datalisttemp != undefined){
							datalisttemp.forEach((val,index) => {
								var sl = 0
								skuselected.forEach((skuitem)=>{
									if(val[colNameSPU] == skuitem[colNameSPU]){
										sl += skuitem[ColNameQty]
									}
								})
								val[ColNameQty]=sl
								var listtemp = []
								blockstyle.forEach((val2, index2) => {
									var style = val2.style
									var obj = {}
									obj['opttype'] = valtype
									obj['divArea'] = divarea
									style.forEach((val3, index3,origin) => {
										if(val3.style.editStyle === 'dddw' && val3.style.dddw.name=='d_nvo_uipage_dwc'){
											var tag_dddwName = val3.style.tag_dddwName
											var tabval =  val[val3.name]
											var customlist = []
											for(var i=0; i<DataObjectExtData.length;i++){
												if(DataObjectExtData[i].dataobjectname == tag_dddwName && DataObjectExtData[i].coldata ==tabval){
													origin[index3].style['value'] = DataObjectExtData[i].coldata
													origin[index3].style['coldisplay'] = DataObjectExtData[i].coldisplay
													origin[index3].style['colValue'] = DataObjectExtData[i].coldisplay
												}
												if(DataObjectExtData[i].dataobjectname == tag_dddwName){
													customlist.push(DataObjectExtData[i])
													origin[index3].style['codeTable'] = customlist
												}
											}
										}else if(val3.name == 'urlfilename' || val3.name == 'urlfilenamex'){
											origin[index3].style['value'] = getApp().globalData.pic_address + val[val3.name]
											origin[index3].style['coldisplay'] = getApp().globalData.pic_address + val[val3.name]
											origin[index3].style['colValue'] = val[val3.name]
										}else if(val3.style.colType == "datetime"){
											var timestr =  val[val3.name]
											if(val3.style.format == "yyyy-MM-dd"){
												timestr = val[val3.name].substring(0,10)
											}
											origin[index3].style['value'] = timestr
											origin[index3].style['coldisplay'] = timestr
											origin[index3].style['colValue'] = timestr
										}else{
											origin[index3].style['value'] = val[val3.name]
											origin[index3].style['coldisplay'] = val[val3.name]
											origin[index3].style['colValue'] = val[val3.name]
										}
									})
									obj['property'] = val2.property
									obj['blockName'] = val2.blockName
									obj['id'] = index2
									obj['blockid'] = index
									obj['data'] = JSON.parse(JSON.stringify(style))
									listtemp.push(JSON.parse(JSON.stringify(obj)))
								})
								datalist.push(listtemp)
							})
						}
						console.log(JSON.parse(JSON.stringify(that.sumdatalist)))
						that.sumdatalist = JSON.parse(JSON.stringify(datalist))
						that.datacategory[that.selecteditem]['products'] = datalist
						console.log(that.datacategory)
						that.datanostyle = datalistpre
						var datacategory = that.datacategory
						datacategory.forEach((val,index)=>{
							var dm = val.dm
							var sl = 0
							if(index == 0){
								skuselected.forEach((val2)=>{
									sl += parseInt(val2[ColNameQty])
								})
								val[ColNameQty] = sl
							}else{
								skuselected.forEach((val2)=>{
									if(val2.dm == dm){
										sl += parseInt(val2[ColNameQty])
									}
								})
								val[ColNameQty] = sl
							}
						})
						that.$forceUpdate()
						console.log(that.datacategory)
					}
				}
			},
			
			navitogood(item,index){
				var that = this
				var divlist = that.divlist
				var rowClick = divlist.style.rowClick
				console.log(divlist)
				that.productindex = index
				var dataitem = that.datanostyle[index]
				if(JSON.stringify(rowClick)=='{}'){
					var rowClickArr = divlist.style.rowClickArr
					var datalist = item
					try{
					rowClickArr.forEach((val)=>{
						var colName = val.colName
						var data = val.data
						var itemcolName = ''
						var itemcolValue = ''
						var event = val.event
						var toDo = event.toDo
						var pagename = event.pageName
						var templetname = event.templetName
						var expArgs = event.expArgs
						var title = event.title
						var colNameSPUval = ''
						var colNameSPU = that.colNameSPU
						datalist.forEach((val2)=>{
							val2.data.forEach((val3)=>{
								if(val3.name == colName){
									itemcolValue = val3.style.colValue
								}
								expArgs.forEach((val4)=>{
									if(val4.colName == val3.name){
										val4['value'] = val3.style.colValue
									}
								})
								if(val3.name == colNameSPU){
									colNameSPUval = val3.style.colValue
								}
							})
						})
						
						if(toDo=='openpage' && itemcolValue==data){
							console.log(that.ColNameQty)
							var skuselected = that.skuselected
							var skuitems = []
							skuselected.forEach((val)=>{
								if(val[colNameSPU] == colNameSPUval){
									skuitems.push(val)
								}
							})
							uni.navigateTo({url:`/pages/multispecs/multispecs?`
												+`templatename=${templetname}`
												+`&pagename=${pagename}`
												+`&menuid=${that.menuid}`
												+`&modid=${that.modid}`
												+`&divArea=`
												+`&title=${title}`
												+`&expArgs=${JSON.stringify(expArgs)}`
												+`&item=${JSON.stringify(item)}`
												+`&dataitem=${JSON.stringify(dataitem)}`
												+`&ColNameQty=${that.ColNameQty}`
												+`&colNameWriteBackBasedOn=${that.colNameWriteBackBasedOn}`
												+`&skuitems=${JSON.stringify(skuitems)}`
											})
							throw 'ENDFOREACH'
						}else if(toDo=='openhalfpage' && itemcolValue==data){
							that.$options.methods.getHalfPage(templetname, pagename,expArgs,that)
							throw 'ENDFOREACH'
						}
					})
					}catch(e){
						
					}
				}
			},
			
			
			selectgood(product, index, index2,colValue){
				var that = this
				console.log(product)
				console.log(index)
				console.log(index2)
				console.log(that.colNameSPU)
				var skuselected = JSON.parse(JSON.stringify(that.skuselected)) 
				var sku = that.datanostyle[index]
				console.log(sku)
				console.log(that.skuselected)
				
				var sumdatalist = that.sumdatalist
				var sumindex = 0
				var productitem = that.datacategory[that.selecteditem].products[index]
				
				sumdatalist.forEach((val,valindex)=>{
					if(JSON.stringify(val) == JSON.stringify(productitem)){
						sumindex = valindex
					}
				})
				console.log(sumindex)
				if(colValue == 0){
					product.data[0].style.colValue = 1
					skuselected.push(sku)
				}else{
					product.data[0].style.colValue = 0
					var ColNameQty = that.ColNameQty
					skuselected.forEach((val,indexval)=>{
						if(val[ColNameQty] == sku[ColNameQty]){
							skuselected.splice(indexval,1)
						}
					})
				}
				if(that.categoryIsFilter!=''){
					that.sumdatalist[sumindex][index2] = product
					that.datacategory[0].products = that.sumdatalist
				}
				console.log(JSON.parse(JSON.stringify(that.sumdatalist)))
				that.skuselected = skuselected
				console.log(that.skuselected)
				that.datacategory[that.selecteditem].products[index][index2] = product
				
				that.$forceUpdate()
			},
			
			getHalfPage(templetName, pageName,expArgs,that){
				var productCode = uni.getStorageSync('productCode')
				var sessionId = uni.getStorageSync('sessionId')
				var projectCode = uni.getStorageSync('projectCode')
				var terminaltype = uni.getStorageSync('terminaltype')
				var dbId = uni.getStorageSync('dbId')
				var userId = uni.getStorageSync('userId')
				var userName = uni.getStorageSync('userName')
				var injson = '{"productCode":"' + productCode + '","terminalType":"' + terminaltype + '","projectCode":"' +
					projectCode + '","dbId":"' + dbId + '","templetName":"' + templetName + '","pageName":"' + pageName +
					'","menuId":"'+that.menuid+'","modId":"' + that.modid + '","sessionId":"' + sessionId + '","userId":"' + userId +
					'","userName":"' + userName + '"}';
				console.log(injson)
				
				uni.showLoading({ title: '加载中' })
				uni.request({
					url: getApp().globalData.app_address + '?method=saas_PageStyle&parse=json',
					data: injson,
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: function(res) {
						var result = res.data;
						console.log(JSON.parse(JSON.stringify(result)))
						uni.hideLoading()
						var div = result.data.div[0]
						that.halfdiv = div
						var datastyle = div.style.colStyle
						var divBlocks = div.divClass.divBlocks
						var dataObject = div.style.dataObject
						var divArea = div.divArea
						that.ColNameQty = div.style.ColNameQty
						that.colNameWriteBackBasedOn = div.style.colNameWriteBackBasedOn
						
						
						if(JSON.stringify(datastyle)!='[]'){
							var listindex = 0
							for(var i=0;i<datastyle.length;i++){
								if(datastyle[i].style.editStyle=='dddw' && datastyle[i].style.dddw.name!='d_nvo_uipage_dwc'&&datastyle[i].style.colVisible){
									datastyle[i].style['typeindex'] = listindex
									listindex++
									var multiselect = util.gettagvalue(datastyle[i].style.tag, 'multiselect')
									if(multiselect == 1){
										that.repeatByColName = datastyle[i].name
										that.repeatByColTag = datastyle[i].style.tag
									}
								}
							}
						}
						
						var DataObjectExtData = uni.getStorageSync('DataObjectExtData')
						var customlist = []
						
						var temconditions = {}
						var conditions = div.style.conditions
						if(div.style.conditions != undefined){
							if(JSON.stringify(expArgs) != '[]' && JSON.stringify(conditions) != '[]' && JSON.stringify(conditions) != undefined){
								var temobj = {}
								for(var m=0; m<conditions.length; m++){
									for(var n=0; n<expArgs.length; n++){
										if(conditions[m].divArea == expArgs[n].divArea){
											var foreignKeyArr = conditions[m].foreignKeyArr
											for(var o=0; o<foreignKeyArr.length; o++){
												if(expArgs[n].colName == foreignKeyArr[o].baseKey){
													temobj[foreignKeyArr[o].foreignKey] = expArgs[n].value
												}
												if(foreignKeyArr[o].type === 'value'){
													temobj[foreignKeyArr[o].foreignKey] = foreignKeyArr[o].value 
												}
											}
										}
									}
								}
								temconditions[divArea] = temobj
							}
						}
						
						for(var k=0;k<datastyle.length;k++){
							if(datastyle[k].style.editStyle=='editmask' && datastyle[k].style.colType=='datetime'){
								datastyle[k].style['starts'] = '1990-01-01'
								datastyle[k].style['ends'] = '2100-01-01'
								datastyle[k].style['placeholder'] = '请选择'
								if(that.opttype == 'billadd'){
									var date = new Date()
									var time = util.formatTime2(date)
									datastyle[k].style['value'] = time
									datastyle[k].style['coldisplay'] =time
									datastyle[k].style['colValue'] = time
								}
							}
						}
						
						var blockstyle = []
						blockstyle = infolistutil.divblocktrans(divBlocks, datastyle)
						var replaceConditions = {}
						var divreplaceColumns = div.style.replaceColumns==undefined?[]:div.style.replaceColumns
						replaceConditions = processInitialData.replaceConditionstrans(replaceConditions, divreplaceColumns,conditions,'')
						
						
						console.log(blockstyle)
						that.halfDivArea = divArea
						that.halfconditions = temconditions
						
						
						var product = that.datacategory[that.selecteditem]['products'][that.productindex]
						var colNameWriteBackBasedOnkey = that.colNameWriteBackBasedOn
						var colNameWriteBackBasedOnvalue = ''
						product.forEach((val2)=>{
							val2.data.forEach((val3)=>{
								if(val3.name == colNameWriteBackBasedOnkey){
									colNameWriteBackBasedOnvalue = val3.style.colValue
								}
							})
						})
						var skuselected = that.skuselected
						skuselected.forEach((skus)=>{
							if(skus[that.colNameWriteBackBasedOn] == colNameWriteBackBasedOnvalue){
								var datalist = []
								var datalisttemp = []
								that.skuitemdata = skus
								datalisttemp.push(skus)
								datalisttemp.forEach((val,index) => {
									var listtemp = []
									blockstyle.forEach((val2, index2) => {
										var style = val2.style
										var obj = {}
										obj['opttype'] = 'update'
										obj['divArea'] = divArea
										style.forEach((val3, index3,origin) => {
											if(val3.style.editStyle === 'dddw' && val3.style.dddw.name=='d_nvo_uipage_dwc'){
												var tag_dddwName = val3.style.tag_dddwName
												var tabval =  val[val3.name]
												var customlist = []
												for(var i=0; i<DataObjectExtData.length;i++){
													if(DataObjectExtData[i].dataobjectname == tag_dddwName && DataObjectExtData[i].coldata ==tabval){
														origin[index3].style['value'] = DataObjectExtData[i].coldata
														origin[index3].style['coldisplay'] = DataObjectExtData[i].coldisplay
														origin[index3].style['colValue'] = DataObjectExtData[i].coldisplay
													}
													if(DataObjectExtData[i].dataobjectname == tag_dddwName){
														customlist.push(DataObjectExtData[i])
														origin[index3].style['codeTable'] = customlist
													}
												}
											}else if(val3.name == 'urlfilename' || val3.name == 'urlfilenamex'){
												origin[index3].style['value'] = getApp().globalData.pic_address + val[val3.name]
												origin[index3].style['coldisplay'] = getApp().globalData.pic_address + val[val3.name]
												origin[index3].style['colValue'] = val[val3.name]
											}else{
												origin[index3].style['value'] = val[val3.name]
												origin[index3].style['coldisplay'] = val[val3.name]
												origin[index3].style['colValue'] = val[val3.name]
											}
										})
										obj['property'] = val2.property
										obj['blockName'] = val2.blockName
										obj['id'] = index2
										obj['blockid'] = index
										obj['data'] = JSON.parse(JSON.stringify(style))
										listtemp.push(JSON.parse(JSON.stringify(obj)))
									})
									datalist.push(listtemp)
								})
								that.halfdatalist = datalist
								that.iscontentdetail1 = true
							}
						})
						if(that.iscontentdetail1)return
						
						var injson2 = '{"productCode":"' + productCode + '","terminalType":"' + terminaltype + '","projectCode":"' +
							projectCode + '","dbId":"' + dbId + '","templetName":"' + templetName + '","pageName":"' + pageName +
							'","menuId":"'+that.menuid+'","modId":"' + that.modid + '","sessionId":"' + sessionId + '","userId":"' + userId +
							'","userName":"' + userName + '","divArea":"' + divArea + '","dataObject":"' + dataObject + 
							'","conditions":' + JSON.stringify(temconditions) + 
							',"replaceConditions":' + JSON.stringify(replaceConditions) + 
							',"pageConditions":' + JSON.stringify(that.pageConditions) + '}';
						console.log('injson2' + injson2)
						uni.request({
							url: getApp().globalData.app_address + '?method=saas_PageDivData&parse=json',
							data: injson2,
							method: 'POST',
							header: {
								'content-type': 'application/x-www-form-urlencoded'
							},
							success: function(res2) {
								var result = res2.data;
								console.log(res2)
								var datalisttemp = result.data.div.value
								var datalist = []
								that.skuitemdata = datalisttemp[0] 
								datalisttemp.forEach((val,index) => {
									var listtemp = []
									blockstyle.forEach((val2, index2) => {
										var style = val2.style
										var obj = {}
										obj['opttype'] = 'update'
										obj['divArea'] = divArea
										style.forEach((val3, index3,origin) => {
											if(val3.style.editStyle === 'dddw' && val3.style.dddw.name=='d_nvo_uipage_dwc'){
												var tag_dddwName = val3.style.tag_dddwName
												var tabval =  val[val3.name]
												var customlist = []
												for(var i=0; i<DataObjectExtData.length;i++){
													if(DataObjectExtData[i].dataobjectname == tag_dddwName && DataObjectExtData[i].coldata ==tabval){
														origin[index3].style['value'] = DataObjectExtData[i].coldata
														origin[index3].style['coldisplay'] = DataObjectExtData[i].coldisplay
														origin[index3].style['colValue'] = DataObjectExtData[i].coldisplay
													}
													if(DataObjectExtData[i].dataobjectname == tag_dddwName){
														customlist.push(DataObjectExtData[i])
														origin[index3].style['codeTable'] = customlist
													}
												}
											}else if(val3.name == 'urlfilename' || val3.name == 'urlfilenamex'){
												origin[index3].style['value'] = getApp().globalData.pic_address + val[val3.name]
												origin[index3].style['coldisplay'] = getApp().globalData.pic_address + val[val3.name]
												origin[index3].style['colValue'] = val[val3.name]
											}else{
												origin[index3].style['value'] = val[val3.name]
												origin[index3].style['coldisplay'] = val[val3.name]
												origin[index3].style['colValue'] = val[val3.name]
											}
										})
										obj['property'] = val2.property
										obj['blockName'] = val2.blockName
										obj['id'] = index2
										obj['blockid'] = index
										obj['data'] = JSON.parse(JSON.stringify(style))
										listtemp.push(JSON.parse(JSON.stringify(obj)))
									})
									datalist.push(listtemp)
								})
								that.halfdatalist = datalist
								that.iscontentdetail1 = true
								console.log(that.halfdatalist)
							},
						})
					},
				})
			},
			
			updatedddwlistvalue(item,listindex,index,itemchanged,divArea){
				var that = this
				console.log(divArea)
				if(index!=''){
					if(divArea == 'dw_datalist'){
						that.$refs.stylesku.updatedddwlistvalue(item,index,itemchanged)
					}
				}
			},
			
			navitosearch(){},
			navitosao(){},
			selectItem(index, mc){
				this.selecteditem = index
				var categoryIsFilter = this.categoryIsFilter
				if(categoryIsFilter != ''){
					var datacategory = this.datacategory
					var dm = datacategory[index].dm
					if(datacategory[index].products != undefined) return
					var sumdatalist = this.sumdatalist
					var products = []
					sumdatalist.forEach((val)=>{
						val.forEach((val3)=>{
							val3.data.forEach((val2)=>{
								if(val2.name == 'fldm' && val2.style.colValue == dm){
									products.push(val)
								}
							})
						})
					})
					datacategory[index]['products'] =products
					this.datacategory = datacategory
				}
			},
			selectxl(index){},
			loadmore(){},
			picerror(index){},
			navitodetail(){
				var that = this
				let pages = getCurrentPages();
				let beforePage = pages[pages.length  -2];
				beforePage.$vm.reload(JSON.stringify(that.skuselected),that.colNameWriteBackBasedOn,that.rowWriteBackRule)
				uni.navigateBack({delta: 1})
			},
			closemask(){
				this.iscontentdetail1 = false
			},
			
			reload(itemstr, selecteditemstr,colNameWriteBackBasedOn){
				var that = this
				var item = JSON.parse(itemstr)
				var selecteditempre = JSON.parse(selecteditemstr)
				that.datacategory[that.selecteditem].products[that.productindex] = item
				var skuselected = that.skuselected
				console.log(colNameWriteBackBasedOn)
				console.log(selecteditempre)
				selecteditempre.forEach((skuitem)=>{
					var itemindex = undefined
					if(JSON.stringify(skuselected)!= '[]'){
						skuselected.forEach((val,index)=>{
							if(val[colNameWriteBackBasedOn] == skuitem[colNameWriteBackBasedOn]){
								itemindex = index
							}
						})
					}
					if(itemindex != undefined){
						skuselected.splice(itemindex,1,skuitem)
					}else{
						skuselected.push(skuitem)
					}
				})
				var datacategory = that.datacategory
				var ColNameQty = that.ColNameQty
				datacategory.forEach((val,index)=>{
					var dm = val.dm
					var sl = 0
					if(index == 0){
						skuselected.forEach((val2)=>{
							sl += parseInt(val2[ColNameQty])
						})
						val[ColNameQty] = sl
					}else{
						skuselected.forEach((val2)=>{
							if(val2.dm == dm){
								sl += parseInt(val2[ColNameQty])
							}
						})
						val[ColNameQty] = sl
					}
				})
				
				that.datacategory = datacategory
				that.skuselected = skuselected
				console.log(skuselected)
				that.$forceUpdate()
			},
		}
	}
</script>
<style>
	.classify{display: flex;height:calc(100vh - 70px);width: 100%;}
	.classify .left{flex:0 0 80px;height: 100%;background-color: #eee;}
	.classify .right{flex: 1;width: 100%;height: 100%;background-color: #eee;}
	.head-title{display: flex;flex-direction: row;align-items: center;padding: 5px 10px;}
	.head-cont{display: flex;flex-direction: row;align-items: center;justify-content: space-between;width: calc(100vw - 30px);}
	.head-title .icon{height: 10px;width: 3px;background-color: #F55C23;display: flex;margin-left: -10px;margin-right: 7px;}
	
</style>
